package com.example.supernote.ui.note

import android.net.Uri
import androidx.compose.foundation.border
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Label
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.example.supernote.R
import com.example.supernote.model.note.commands.AbstractCommand
import com.example.supernote.model.note.commands.Insert.GenerateCodeCommand
import com.example.supernote.model.note.commands.Insert.GenerateImageCommand
import com.example.supernote.model.note.commands.Insert.InsertLinkCommand
import com.example.supernote.model.note.commands.Insert.OcrAudioCommand
import com.example.supernote.model.note.commands.Insert.OcrImageCommand
import com.example.supernote.model.note.commands.Insert.UploadAudioCommand
import com.example.supernote.model.note.commands.Insert.UploadImageCommand
import com.example.supernote.model.note.commands.Insert.UploadVideoCommand
import com.example.supernote.model.note.commands.Layout.InsertTableCommand
import com.example.supernote.model.note.commands.Text.ExtractOutlineCommand
import com.example.supernote.model.note.commands.Text.ExtractSummaryCommand
import com.example.supernote.model.note.commands.Text.FontColorCommand
import com.example.supernote.model.note.commands.Text.FontSizeCommand
import com.example.supernote.model.note.commands.Text.PolishTextCommand
import com.example.supernote.model.note.commands.Text.TextGenerateCommand
import com.example.supernote.model.note.commands.Text.TranslateTextCommand
import com.example.supernote.model.note.context.Context
import com.example.supernote.model.note.operations.AbstractOpration
import com.example.supernote.ui.components.UniformButton
import com.example.supernote.ui.components.UniformIcon
import com.example.supernote.ui.components.UniformToast
import com.example.supernote.ui.note.components.ChangeAudioToText
import com.example.supernote.ui.note.components.ShowAiDialog
import com.example.supernote.ui.note.components.ShowColorPicker
import com.example.supernote.ui.note.components.ShowGeneratorDialog
import com.example.supernote.ui.note.components.ShowGetorDialog
import com.example.supernote.ui.note.components.ShowLinkDialog
import com.example.supernote.ui.note.components.ShowSizePicker
import com.example.supernote.ui.note.components.ShowTableDialog
import com.example.supernote.ui.note.components.ShowTextOcrDialog
import com.example.supernote.ui.note.utils.SelectAudioContract
import com.example.supernote.ui.note.utils.SelectPhotoContract
import com.example.supernote.ui.note.utils.SelectVideoContract
import com.example.supernote.ui.note.utils.TakePhotoContract
import com.example.supernote.ui.note.utils.TakeVideoContract
import com.example.supernote.ui.utils.MarkdownText
import com.example.supernote.ui.utils.getSystemPrompt
import java.text.SimpleDateFormat
import java.util.Locale

@Composable
fun NoteContent(
    modifier: Modifier,
    uiState: NoteUiState,
    editContext: (context: TextFieldValue) -> Unit,
    editTitle: (title: String) -> Unit,
    saveFile: () -> Unit,
    changeEditMode: () -> Unit,
    apiByPrompt: ((String) -> Unit, Map<String, String>) -> Unit,
    imageGenerateApiByPrompt: ((String) -> Unit, Map<String, String>) -> Unit,
    imageOCRApi: ((String) -> Unit, String, String) -> Unit,
    translateTextApi: ((String) -> Unit, Map<String, String>) -> Unit,
    audioApi: (updateTemplate: (String) -> Unit, updateProgress: (Float) -> Unit, Uri, android.content.Context) -> Unit,
    execute: (command: AbstractCommand, context: Context) -> Unit,
    changeOperation: (choice: String) -> Unit
) {
    val curOperation = uiState.curOperation
    val note = uiState.note!!
    val context = note.context
    val edit = uiState.editMode
    val ops = uiState.opsTitle
    val formattedTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(
        note.lastModify
    )

    // 笔记信息：DisplayNoteInfo()
    Column(
        modifier = modifier
    ) {
        HorizontalDivider(
            modifier = Modifier
                .padding(
                    15.dp, 5.dp
                ),
            thickness = 3.dp
        )
        // 中上部：文件的部分信息
        Row(
            modifier = Modifier.padding(15.dp, 0.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Box(
                modifier = Modifier.weight(4f),
                contentAlignment = Alignment.CenterStart
            ) {
                if (edit)
                    TextField(
                        value = note.title,
                        modifier = Modifier
                            .padding(end = 5.dp)
                            .fillMaxWidth(),
                        onValueChange = { editTitle(it) },
                        singleLine = true,
                        label = {
                            Text(
                                text = stringResource(R.string.note_article_title),
                                color = Color.Gray,
                                overflow = TextOverflow.Visible
                            )
                        }
                    )
                else
                    Row {
                        UniformIcon(imageVector = Icons.Filled.Label)
                        Spacer(modifier = Modifier.width(5.dp))
                        Text(
                            text = note.title,
                            modifier = Modifier
                                .padding(end = 5.dp)
                                .fillMaxWidth()
                                .horizontalScroll(rememberScrollState()),
                            style = MaterialTheme.typography.titleMedium,
                        )
                    }
            }
            Box(
                modifier = Modifier.weight(1f),
                contentAlignment = Alignment.CenterEnd
            ) {
                UniformButton(
                    onClick = { changeEditMode() },
                    text = if (edit) stringResource(R.string.note_mode_read) else stringResource(R.string.note_mode_edit),
                    modifier = Modifier.padding(0.dp)
                )
            }
        }
        Row(
            modifier = Modifier.padding(15.dp, 5.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Box(
                modifier = Modifier.weight(3f),
                contentAlignment = Alignment.CenterStart
            ) {
                Text(
                    text = "${stringResource(R.string.note_counts)}: ${context.article.text.length}",
                    style = MaterialTheme.typography.bodyMedium,
                    modifier = Modifier
                        .padding(end = 8.dp)
                )
            }
            Box(
                contentAlignment = Alignment.CenterEnd
            ) {
                Text(
                    text = "${stringResource(R.string.note_edit_time)}: $formattedTime",
                    style = MaterialTheme.typography.bodyMedium,
                    modifier = Modifier
                        .padding(start = 8.dp)
                )
            }
        }

        HorizontalDivider(
            modifier = Modifier
                .padding(
                    15.dp, 0.dp
                ),
            thickness = 3.dp
        )

        Spacer(modifier = Modifier.height(16.dp))
        // 中下部：输入框
        if (edit) {
            Box(
                modifier = Modifier
                    .weight(1f)
                    .padding(15.dp, 0.dp),
                contentAlignment = Alignment.CenterStart
            ) {
                TextField(
                    value = context.article,
                    maxLines = Int.MAX_VALUE,
                    modifier = Modifier
                        .fillMaxSize(),
                    onValueChange = { editContext(it) }
                )
            }

            HorizontalDivider(
                modifier = Modifier
                    .padding(
                        0.dp, 10.dp, 0.dp, 5.dp
                    ),
                thickness = 3.dp
            )

            // 按钮
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(15.dp, 0.dp)
            ) {
                for ((key, obj) in ops) {
                    UniformButton(
                        onClick = { changeOperation(key) },
                        imageVector = obj.imageVector,
                        text = stringResource(obj.stringResId),
                        modifier = Modifier
                            .weight(1f)
                            .padding(5.dp, 0.dp)
                    )
                }
            }
            HorizontalDivider(
                modifier = Modifier
                    .padding(
                        0.dp, 5.dp, 0.dp, 5.dp
                    ),
                thickness = 3.dp
            )
            ops[curOperation]?.let {
                RenderCommands(
                    operation = it,
                    context = context,
                    saveFile = saveFile,
                    execute = execute,
                    apiByPrompt = apiByPrompt,
                    imageGenerateApiByPrompt = imageGenerateApiByPrompt,
                    imageOCRApi = imageOCRApi,
                    translateTextApi = translateTextApi,
                    audioApi = audioApi
                )
            }
        } else {
            MarkdownText(context.parseContext())
        }
    }
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun RenderCommands(
    operation: AbstractOpration,
    context: Context,
    saveFile: () -> Unit,
    execute: (command: AbstractCommand, context: Context) -> Unit,
    apiByPrompt: ((String) -> Unit, Map<String, String>) -> Unit,
    imageGenerateApiByPrompt: ((String) -> Unit, Map<String, String>) -> Unit,
    imageOCRApi: ((String) -> Unit, String, String) -> Unit,
    translateTextApi: ((String) -> Unit, Map<String, String>) -> Unit,
    audioApi: (updateTemplate: (String) -> Unit, updateProgress: (Float) -> Unit, Uri, android.content.Context) -> Unit,
) {
    val scrollState = rememberScrollState()
    val configuration = LocalConfiguration.current
    val screenWidthDp = configuration.screenWidthDp.dp
    val toastContext = LocalContext.current

    // 上传图片部分
    var showImagePicker by remember { mutableStateOf(false) }

    val dealImage: (Uri, String) -> Unit = { imageUri, imageName ->
        val newContext = context.copy()
        newContext.uri = imageUri
        newContext.name = imageName
        execute(UploadImageCommand(), newContext)
        showImagePicker = false
    }

    if (showImagePicker) {
        ShowGetorDialog(
            onCancel = { showImagePicker = false },
            onConfirm = dealImage,
            contractUpload = SelectPhotoContract(),
            contractCamera = TakePhotoContract(),
            dialogTitle = stringResource(R.string.note_upload_image)
        )
    }

    // 上传音频部分
    var showAudioPicker by remember { mutableStateOf(false) }

    val dealAudio: (Uri, String) -> Unit = { audioUri, audioName ->
        val newContext = context.copy()
        newContext.uri = audioUri
        newContext.name = audioName
        execute(UploadAudioCommand(), newContext)
        showAudioPicker = false
    }

    if (showAudioPicker) {
        ShowGetorDialog(
            onCancel = { showAudioPicker = false },
            onConfirm = dealAudio,
            contractUpload = SelectAudioContract(),
            contractCamera = null,
            dialogTitle = stringResource(R.string.note_upload_audio)
        )
    }

    // 上传视频部分
    var showVideoPicker by remember { mutableStateOf(false) }

    val dealVideo: (Uri, String) -> Unit = { videoUri, videoName ->
        val newContext = context.copy()
        newContext.uri = videoUri
        newContext.name = videoName
        execute(UploadVideoCommand(), newContext)
        showVideoPicker = false
    }

    if (showVideoPicker) {
        ShowGetorDialog(
            onCancel = { showVideoPicker = false },
            onConfirm = dealVideo,
            contractUpload = SelectVideoContract(),
            contractCamera = TakeVideoContract(),
            dialogTitle = stringResource(R.string.note_upload_video)
        )
    }

    // 生成代码部分
    var showCodeDialog by remember { mutableStateOf(false) }

    val dealCode: (String) -> Unit = { aiCode ->
        val newContext = context.copy()
        newContext.generateText = aiCode
        execute(GenerateCodeCommand(), newContext)
        showCodeDialog = false
    }

    if (showCodeDialog) {
        val dialogTitle = stringResource(R.string.note_gen_code)
        ShowGeneratorDialog(
            onCancel = { showCodeDialog = false },
            onGenerate = apiByPrompt,
            onConfirm = dealCode,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle),
                "inputLabel" to stringResource(R.string.note_gencode_tip),
            )
        )
    }

    // 生成图片部分
    var showImageDialog by remember { mutableStateOf(false) }

    val dealGenImage: (String) -> Unit = { imgUrl ->
        val newContext = context.copy()
        newContext.generateText = imgUrl
        execute(GenerateImageCommand(), newContext)
        showImageDialog = false
    }

    if (showImageDialog) {
        val dialogTitle = stringResource(R.string.note_gen_image)
        ShowGeneratorDialog(
            onCancel = { showImageDialog = false },
            onGenerate = imageGenerateApiByPrompt,
            onConfirm = dealGenImage,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle),
                "inputLabel" to stringResource(R.string.note_genimage_tip)
            )
        )
    }

    // 大纲部分
    var showOutlineDialog by remember { mutableStateOf(false) }

    val dealOutlineText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(ExtractOutlineCommand(), newContext)
        showOutlineDialog = false
    }

    if (showOutlineDialog) {
        val dialogTitle = stringResource(R.string.note_extract_outline)
        ShowAiDialog(
            onCancel = { showOutlineDialog = false },
            onGenerate = apiByPrompt,
            onConfirm = dealOutlineText,
            context = context,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle)
            )
        )
    }

    // 摘要部分
    var showSummaryDialog by remember { mutableStateOf(false) }
    val dealSummaryText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(ExtractSummaryCommand(), newContext)
        showSummaryDialog = false
    }

    if (showSummaryDialog) {
        val dialogTitle = stringResource(R.string.note_extract_summary)
        ShowAiDialog(
            onCancel = { showSummaryDialog = false },
            onGenerate = apiByPrompt,
            onConfirm = dealSummaryText,
            context = context,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle),
            )
        )
    }

    // 文本润色部分
    var showPolishDialog by remember { mutableStateOf(false) }

    val dealPolishText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(PolishTextCommand(), newContext)
        showPolishDialog = false
    }

    if (showPolishDialog) {
        val dialogTitle = stringResource(R.string.note_polish_text)
        ShowAiDialog(
            onCancel = { showPolishDialog = false },
            onGenerate = apiByPrompt,
            onConfirm = dealPolishText,
            changeContextRange = { context.selection = TextRange(0, context.article.text.length) },
            context = context,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle)
            )
        )
    }

    // 文本生成部分
    var showTextGenerateDialog by remember { mutableStateOf(false) }

    val dealGenerateText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(TextGenerateCommand(), newContext)
        showTextGenerateDialog = false
    }

    if (showTextGenerateDialog) {
        val dialogTitle = stringResource(R.string.note_text_generate)
        ShowGeneratorDialog(
            onCancel = { showTextGenerateDialog = false },
            onGenerate = apiByPrompt,
            onConfirm = dealGenerateText,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle),
                "inputLabel" to stringResource(R.string.note_gentext_tip),
            )
        )
    }

    // 文本翻译部分
    var showTranslateDialog by remember { mutableStateOf(false) }

    val dealTranslateText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(TranslateTextCommand(), newContext)
        showTranslateDialog = false
    }

    if (showTranslateDialog) {
        val dialogTitle = stringResource(R.string.note_translation)
        ShowAiDialog(
            onCancel = { showTranslateDialog = false },
            onGenerate = translateTextApi,
            onConfirm = dealTranslateText,
            context = context,
            otherInfos = mapOf(
                "dialogTitle" to dialogTitle,
                "systemPrompt" to getSystemPrompt(dialogTitle)
            )
        )
    }

    // 文本识别部分
    var showOcrDialog by remember { mutableStateOf(false) }

    val dealOcrText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(OcrImageCommand(), newContext)
        showOcrDialog = false
    }

    if (showOcrDialog) {
        ShowTextOcrDialog(
            onCancel = { showOcrDialog = false },
            onGenerate = imageOCRApi,
            onConfirm = dealOcrText
        )
    }

    // 音频转文字部分
    var changeAudioToText by remember { mutableStateOf(false) }

    val dealAudioText: (String) -> Unit = { aiText ->
        val newContext = context.copy()
        newContext.generateText = aiText
        execute(OcrAudioCommand(), newContext)
        changeAudioToText = false
    }

    if (changeAudioToText) {
        ChangeAudioToText(
            onCancel = { changeAudioToText = false },
            onGenerate = audioApi,
            onConfirm = dealAudioText
        )
    }

    // 字体颜色
    var showColorPicker by remember { mutableStateOf(false) }
    val dealFontColor: (String) -> Unit = { colorHex ->
        val newContext = context.copy()
        newContext.generateText = colorHex
        execute(FontColorCommand(), newContext)
        showColorPicker = false
    }
    if (showColorPicker) {
        ShowColorPicker(
            onCancel = { showColorPicker = false },
            onConfirm = dealFontColor
        )
    }

    // 字体大小
    var showSizePicker by remember { mutableStateOf(false) }
    val dealFontSize: (String) -> Unit = { fontSize ->
        val newContext = context.copy()
        newContext.generateText = fontSize
        execute(FontSizeCommand(), newContext)
        showSizePicker = false
    }
    if (showSizePicker) {
        ShowSizePicker(
            onCancel = { showSizePicker = false },
            onConfirm = dealFontSize
        )
    }

    // 插入链接
    var showLinkDialog by remember { mutableStateOf(false) }
    val dealLink: (String, String) -> Unit = { name, url ->
        val newContext = context.copy()
        newContext.generateText = "![$name]($url)"
        execute(InsertLinkCommand(), newContext)
        showLinkDialog = false
    }
    if (showLinkDialog) {
        ShowLinkDialog(
            onCancel = { showLinkDialog = false },
            onConfirm = dealLink
        )
    }

    // 插入表格
    var showTableDialog by remember { mutableStateOf(false) }
    val dealTable: (String) -> Unit = { template ->
        val newContext = context.copy()
        newContext.generateText = template
        execute(InsertTableCommand(), newContext)
        showTableDialog = false
    }
    if (showTableDialog) {
        ShowTableDialog(
            onCancel = { showTableDialog = false },
            onConfirm = dealTable
        )
    }

    Column(
        modifier = Modifier
            .padding(15.dp, 0.dp)
            .height(220.dp)
            .verticalScroll(scrollState)
    ) {
        for (group in operation.getGroups()) {
            Column(
                modifier = Modifier
                    .padding(8.dp)
                    .border(
                        width = 1.dp,
                        color = Color.Gray,
                        shape = RoundedCornerShape(5.dp)
                    )
            ) {
                Row(
                    modifier = Modifier.padding(start = 10.dp, top = 5.dp)
                ) {
                    Text(
                        text = stringResource(group.stringResId),
                        style = MaterialTheme.typography.titleMedium
                    )
                }

                FlowRow(
                    modifier = Modifier
                        .widthIn(min = screenWidthDp)
                ) {
                    group.getCommands().forEach {
                        val t = stringResource(R.string.note_save_success)
                        when (stringResource(it.stringResId)) {
                            stringResource(R.string.note_upload_image) -> {
                                UniformButton(
                                    onClick = { showImagePicker = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_upload_audio) -> {
                                UniformButton(
                                    onClick = { showAudioPicker = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_upload_video) -> {
                                UniformButton(
                                    onClick = { showVideoPicker = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_gen_image) -> {
                                UniformButton(
                                    onClick = { showImageDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_gen_code) -> {
                                UniformButton(
                                    onClick = { showCodeDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_extract_outline) -> {
                                UniformButton(
                                    onClick = { showOutlineDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_extract_summary) -> {
                                UniformButton(
                                    onClick = { showSummaryDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_polish_text) -> {
                                UniformButton(
                                    onClick = { showPolishDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_text_generate) -> {
                                UniformButton(
                                    onClick = { showTextGenerateDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_translation) -> {
                                UniformButton(
                                    onClick = { showTranslateDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_ocr) -> {
                                UniformButton(
                                    onClick = { showOcrDialog = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_convert_audio) -> {
                                UniformButton(
                                    onClick = { changeAudioToText = true },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                            stringResource(R.string.note_font_color) -> UniformButton(
                                onClick = { showColorPicker = true },
                                text = stringResource(it.stringResId),
                                modifier = Modifier
                                    .padding(5.dp)
                            )
                            stringResource(R.string.note_font_size) -> UniformButton(
                                onClick = { showSizePicker = true },
                                text = stringResource(it.stringResId),
                                modifier = Modifier
                                    .padding(5.dp)
                            )
                            stringResource(R.string.note_table) -> UniformButton(
                                onClick = { showTableDialog = true },
                                text = stringResource(it.stringResId),
                                modifier = Modifier
                                    .padding(5.dp)
                            )
                            stringResource(R.string.note_insert_link) -> UniformButton(
                                onClick = { showLinkDialog = true },
                                text = stringResource(it.stringResId),
                                modifier = Modifier
                                    .padding(5.dp)
                            )
                            stringResource(R.string.note_save) -> UniformButton(
                                onClick = { saveFile()
                                    UniformToast(toastContext, t) },
                                text = stringResource(it.stringResId),
                                modifier = Modifier
                                    .padding(5.dp)
                            )
                            else -> {
                                UniformButton(
                                    onClick = { execute(it, context) },
                                    text = stringResource(it.stringResId),
                                    modifier = Modifier
                                        .padding(5.dp)
                                )
                            }
                        }
                    }
                }
            }
        }
    }
}